package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mes.domain.LnyRmOrderDetail;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.LnyStoragePut;
import com.ruoyi.mes.service.ILnyStoragePutService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库管理Controller
 * 
 * @author CFL
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/mes/put_storage")
public class LnyStoragePutController extends BaseController
{
    @Autowired
    private ILnyStoragePutService lnyStoragePutService;

    /**
     * 查询入库管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:put_storage:list')")
    @GetMapping("/list")
    public TableDataInfo list(LnyStoragePut lnyStoragePut)
    {
        startPage();
        List<LnyStoragePut> list = lnyStoragePutService.selectLnyStoragePutList(lnyStoragePut);
        return getDataTable(list);
    }

    /**
     * 导出入库管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:put_storage:export')")
    @Log(title = "入库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LnyStoragePut lnyStoragePut)
    {
        List<LnyStoragePut> list = lnyStoragePutService.selectLnyStoragePutList(lnyStoragePut);
        ExcelUtil<LnyStoragePut> util = new ExcelUtil<LnyStoragePut>(LnyStoragePut.class);
        util.exportExcel(response, list, "入库管理数据");
    }

    /**
     * 获取入库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:put_storage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(lnyStoragePutService.selectLnyStoragePutById(id));
    }

    /**
     * 新增入库管理
     */
    @PreAuthorize("@ss.hasPermi('mes:put_storage:add')")
    @Log(title = "入库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LnyStoragePut lnyStoragePut)
    {
        return toAjax(lnyStoragePutService.insertLnyStoragePut(lnyStoragePut));
    }

    /**
     * 采购入库的入库按钮调用查询接口
     */
    @PreAuthorize("@ss.hasPermi('mes:put_storage:buy:check:query')")
    @GetMapping(value = "/buy/check/{purchaseSn}")
    public TableDataInfo buyList(@PathVariable("purchaseSn") String purchaseSn)
    {
        List<LnyRmOrderDetail> list = lnyStoragePutService.selectFromBuy(purchaseSn);
        return getDataTable(list);
    }

    /**
     * 完工入库后改库存数据
     */
    @PreAuthorize("@ss.hasPermi('mes:put_storage:produce')")
    @Log(title = "完工入库", businessType = BusinessType.UPDATE)
    @PutMapping("/produce")
    public AjaxResult addStoreroomFromProduce(@RequestBody LnyStoragePut lnyStoragePut)
    {
        return toAjax(lnyStoragePutService.updateStoreroomFromProduce(lnyStoragePut));
    }

    /**
     * 采购入库后改库存数据
     */
    @PreAuthorize("@ss.hasPermi('mes:put_storage:buy')")
    @Log(title = "采购入库", businessType = BusinessType.UPDATE)
    @PutMapping("/buy")
    public AjaxResult addStoreroomFromBuy(@RequestBody List<LnyStoragePut> lnyStoragePut)
    {
        return toAjax(lnyStoragePutService.updateStoreroomFromBuy(lnyStoragePut));
    }

    /**
     * 修改入库管理
     */
    @PreAuthorize("@ss.hasPermi('mes:put_storage:edit')")
    @Log(title = "入库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LnyStoragePut lnyStoragePut)
    {
        return toAjax(lnyStoragePutService.updateLnyStoragePut(lnyStoragePut));
    }

    /**
     * 删除入库管理
     */
    @PreAuthorize("@ss.hasPermi('mes:put_storage:remove')")
    @Log(title = "入库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lnyStoragePutService.deleteLnyStoragePutByIds(ids));
    }
}
